home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 679 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.4 KB

  1. Path: user1.mnsinc.com!huang
  2. From: huang@mnsinc.com (Szu-Wen Huang)
  3. Newsgroups: comp.lang.c,comp.std.c,finet.atk.kielet.c
  4. Subject: Re: TYPEDEF and Watcom C++ 10.5
  5. Followup-To: comp.lang.c,comp.std.c,finet.atk.kielet.c
  6. Date: 1 Apr 1996 14:15:26 GMT
  7. Organization: Monumental Network Systems
  8. Distribution: world
  9. Message-ID: <4joodu$m9p@news1.mnsinc.com>
  10. References: <4jlu1r$cs7@nic.dataphone.se>
  11. NNTP-Posting-Host: user1.mnsinc.com
  12. X-Newsreader: TIN [version 1.2 PL2]
  13.  
  14. Jarmo Paavilainen (skorpio@dataphone.se) wrote:
  15.  
  16. : typedef struct
  17. : {
  18. : WORD    CheckSum;
  19. : WORD    Version;
  20. : BYTE    PatchLevel;
  21. : BYTE    Name[21];
  22. : WORD    MarkerVersion;
  23. : }VERSION_TAG_STRUCT;
  24.  
  25. : Shouldn't sizeof(VERSION_TAG_STRUCT) always result in 28. By other words
  26. : shouldn't WORD always be 16 bits and BYTE 8 bits.
  27.  
  28. : If so why does my compiler claim that sizeof(VERSION_TAG_STRUCT) == 34.
  29. : All this in 32 bit OS/2 PM and Watcom C++ 10.5
  30.  
  31. You show two misconceptions.  First of all, C guarantees you a minimum
  32. number of bits you can use for each type, but does not guarantee that your
  33. compiler will not give you more.  Secondly, even if the additive size of
  34. each field in a struct is a certain number of bytes, the compiler is still
  35. free to pad the structure (usually to align to word boundaries), or to
  36. optimize for speed.  Let me answer your last question with another
  37. question:  Why do you think sizeof() is provided if you can count on the
  38. structure being 28 bytes?  ;)
  39.